package com.byedu.course.util;

import com.byedu.domain.focus.FocusKpiDO;
import com.byedu.domain.focus.FocusProduceDO;
import com.byedu.domain.focus.vo.FocusKpiVO;
import com.byedu.domain.focus.vo.FocusProjectVO;
import com.byedu.domain.focus.vo.FocusUserVO;
import com.byedu.domain.focus.vo.FocusWorkorderVO;
import com.byedu.domain.focus.vo.enumvos.FocusStatusExcuteEnum;
import com.byedu.util.FileUploadUtil;
import com.byedu.util.FileUtil;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.HSSFColor;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;

/**
 *@Project: excel
 *@Author: chenssy
 *@Date: 2013-4-4
 *@Copyright:  chenssy All rights reserved.
 */
public class UserExportExcelUtil {

    public static  String ExcelsavePath =FileUploadUtil.focusdirPath;
    public static  String ExcelexportPath = FileUploadUtil.focusbaseurlname;
    public static  String MENBERS = "menbers.xls";
    public static  String PRODUCES = "produces.xls";
    public static  String PROJECTS = "projects.xls";
    public static  String KPIS = "kpis.xls";
    public static  String WEEK = "week.xls";
    public static  String MONTH = "month.xls";
    public static  String QUATER = "quater.xls";
    public static  String YEAR = "year.xls";
    public static  String WORKORDER = "workorder.xls";

    public static String userExcelexpot(List<FocusUserVO> focusUserVOList,FocusUserVO adminUser) {
        FileUtil.createdir(ExcelsavePath);
        //第一步创建workbook
        HSSFWorkbook wb = new HSSFWorkbook();
        //第二步创建sheet
        HSSFSheet sheet = wb.createSheet("公司员工信息表");
//        sheet.setColumnWidth((short)column,(short)width);
        //第三步创建行row:添加表头0行
        HSSFRow row = sheet.createRow(0);
        HSSFCellStyle  style = wb.createCellStyle();
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);  //居中
        style.setWrapText(true); //设置自动大小

        //第四步创建单元格
        createCell(row,0,style,"姓名",sheet,15);
        createCell(row,1,style,"部门",sheet,15);
        createCell(row,2,style,"职位",sheet,15);
        createCell(row,3,style,"电话",sheet,15);
        createCell(row,4,style,"邮箱",sheet,20);

        //第五步插入数据

        for (int i = 0; i < focusUserVOList.size(); i++) {
            FocusUserVO focusUserVO = focusUserVOList.get(i);
            //创建行
            row = sheet.createRow(i+1);
            //创建单元格并且添加数据
            row.createCell(0).setCellValue(focusUserVO.getUsername());
            row.createCell(1).setCellValue(focusUserVO.getDepartment());
            row.createCell(2).setCellValue(focusUserVO.getPosition());
            row.createCell(3).setCellValue(focusUserVO.getPhone());
            row.createCell(4).setCellValue(focusUserVO.getEmail());
        }

        //第六步将生成excel文件保存到指定路径下
        try {
            FileOutputStream fout = new FileOutputStream(ExcelsavePath + adminUser.getUsername()+MENBERS);
            wb.write(fout);
            fout.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

//        System.out.println("Excel文件生成成功...");
        return ExcelexportPath + adminUser.getUsername()+ MENBERS;
    }

    public static String workorderExcelexpot(List<FocusWorkorderVO> workorderList,FocusUserVO adminUser) {
        FileUtil.createdir(ExcelsavePath);
        //第一步创建workbook
        HSSFWorkbook wb = new HSSFWorkbook();
        //第二步创建sheet
        HSSFSheet sheet = wb.createSheet("我的工单");
//        sheet.setColumnWidth((short)column,(short)width);
        //第三步创建行row:添加表头0行
        HSSFRow row = sheet.createRow(0);
        HSSFCellStyle  style = wb.createCellStyle();
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);  //居中
        style.setWrapText(true); //设置自动大小

        //第四步创建单元格

        createCell(row,0,style,"项目名称",sheet,20);
        createCell(row,1,style,"公司名称",sheet,20);
        createCell(row,2,style,"Tc号",sheet,20);
        createCell(row,3,style,"沟通证据下载",sheet,80);
        createCell(row,4,style,"执行人",sheet,10);
        createCell(row,5,style,"执行内容下载",sheet,80);
        createCell(row,6,style,"开始时间",sheet,20);
        createCell(row,7,style,"截止时间",sheet,20);
        createCell(row,8,style,"完成时间",sheet,20);
        createCell(row,9,style,"完成状态",sheet,10);
        createCell(row,10,style,"项目目录",sheet,30);
        createCell(row,11,style,"取消原因",sheet,30);
        for (int i = 0; i < workorderList.size(); i++) {
            FocusWorkorderVO focusWorkorderVO = workorderList.get(i);
            //创建行
            row = sheet.createRow(i+1);
            //创建单元格并且添加数据
            row.createCell(0).setCellValue(focusWorkorderVO.getName());
            row.createCell(1).setCellValue(focusWorkorderVO.getProject().getName());
            row.createCell(2).setCellValue(focusWorkorderVO.getProject().getTc());
            row.createCell(3).setCellValue(focusWorkorderVO.getCertifile());
            if(focusWorkorderVO.getUser()!=null) {
                row.createCell(4).setCellValue(focusWorkorderVO.getUser().getUsername());
            }
            row.createCell(5).setCellValue(focusWorkorderVO.getDecfile());
            row.createCell(6).setCellValue(focusWorkorderVO.getStarttime());
            row.createCell(7).setCellValue(focusWorkorderVO.getExcuttime());
            row.createCell(8).setCellValue(focusWorkorderVO.getFinishtime());
            row.createCell(9).setCellValue(focusWorkorderVO.getStatus().getValue());
            if(focusWorkorderVO.getStatus().getCode() == FocusStatusExcuteEnum.EO4.getCode() ) {
                row.createCell(11).setCellValue(focusWorkorderVO.getStatustr());
            }else{
                row.createCell(10).setCellValue(focusWorkorderVO.getStatustr());
            }
        }
        try {
            FileOutputStream fout = new FileOutputStream(ExcelsavePath + adminUser.getUsername()+ WORKORDER);
            wb.write(fout);
            fout.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return ExcelexportPath + adminUser.getUsername()+ WORKORDER;
    }


    public static String produceExcelexpot(List<FocusProduceDO> produceList,FocusUserVO adminUser) {
        FileUtil.createdir(ExcelsavePath);
        //第一步创建workbook
        HSSFWorkbook wb = new HSSFWorkbook();
        //第二步创建sheet
        HSSFSheet sheet = wb.createSheet("公司合作产品表");
//        sheet.setColumnWidth((short)column,(short)width);
        //第三步创建行row:添加表头0行
        HSSFRow row = sheet.createRow(0);
        HSSFCellStyle  style = wb.createCellStyle();
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);  //居中
        style.setWrapText(true); //设置自动大小

        //第四步创建单元格

        createCell(row,0,style,"产品名称",sheet,10);
        createCell(row,1,style,"公司名称",sheet,20);
        createCell(row,2,style,"税人识别号",sheet,20);
        createCell(row,3,style,"开票注册地址",sheet,25);
        createCell(row,4,style,"开票单位电话",sheet,20);
        createCell(row,5,style,"开户行",sheet,30);
        createCell(row,6,style,"开户账号",sheet,20);
        createCell(row,7,style,"产品联系人",sheet,20);
        createCell(row,8,style,"联系电话",sheet,20);
        createCell(row,9,style,"产品描述",sheet,30);
        for (int i = 0; i < produceList.size(); i++) {
            FocusProduceDO focusProduceDO = produceList.get(i);
            //创建行
            row = sheet.createRow(i+1);
            //创建单元格并且添加数据
            row.createCell(0).setCellValue(focusProduceDO.getProducename());
            row.createCell(1).setCellValue(focusProduceDO.getCustomer());
            row.createCell(2).setCellValue(focusProduceDO.getBillcode());
            row.createCell(3).setCellValue(focusProduceDO.getAddress());
            row.createCell(4).setCellValue(focusProduceDO.getTelephone());
            row.createCell(5).setCellValue(focusProduceDO.getOpenaddress());
            row.createCell(6).setCellValue(focusProduceDO.getOpencode());
            row.createCell(7).setCellValue(focusProduceDO.getConnector());
            row.createCell(8).setCellValue(focusProduceDO.getConnectorphone());
            row.createCell(9).setCellValue(focusProduceDO.getDescription());
        }
        try {
            FileOutputStream fout = new FileOutputStream(ExcelsavePath + adminUser.getUsername()+ PRODUCES);
            wb.write(fout);
            fout.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return ExcelexportPath + adminUser.getUsername()+ PRODUCES;
    }


    public static String projectExcelexpot(List<FocusProjectVO> projectList,FocusKpiDO focusKpiDO,FocusUserVO adminUser) {
        FileUtil.createdir(ExcelsavePath);
        //第一步创建workbook
        HSSFWorkbook wb = new HSSFWorkbook();
        //第二步创建sheet
        HSSFSheet sheet = wb.createSheet("项目表");
        HSSFRow row = sheet.createRow(0);
        HSSFCellStyle  style = wb.createCellStyle();



        createCell(row,0,style,"年费季度",sheet,20);
        createCell(row,1,style,"项目名称",sheet,20);
        createCell(row,2,style,"所属产品",sheet,20);
        createCell(row,3,style,"隶属人",sheet,20);
        createCell(row,4,style,"下单人",sheet,20);
        createCell(row,5,style,"产品说明",sheet,30);
        createCell(row,6,style,"TC号",sheet,20);
        createCell(row,7,style,"计划金额",sheet,20);
        createCell(row,8,style,"计划支出",sheet,10);
        createCell(row,9,style,"计划毛利",sheet,8);

        createCell(row,10,style,"PO号",sheet,20);
        createCell(row,11,style,"PO时间",sheet,10);
        createCell(row,12,style,"PO金额",sheet,10);
        createCell(row,13,style,"实际支出",sheet,10);
        createCell(row,14,style,"实际毛利",sheet,10);
        createCell(row,15,style,"开票号",sheet,20);
        createCell(row,16,style,"开票金额",sheet,20);
        createCell(row,17,style,"开票时间",sheet,10);
        createCell(row,18,style,"回款时间",sheet,10);


        createCell(row,19,style,"项目进度",sheet,20);

        for (int i = 0; i <= projectList.size(); i++) {
            //创建行
            row = sheet.createRow(i+1);
            if(i < projectList.size()){
                FocusProjectVO focusProjectVO = projectList.get(i);
                //创建单元格并且添加数据
                row.createCell(0).setCellValue(focusProjectVO.getPryear()+"年第"+focusProjectVO.getPrjidu()+"季度");
                row.createCell(1).setCellValue(focusProjectVO.getName());
                if(focusProjectVO.getProduce()!=null) {
                    row.createCell(2).setCellValue(focusProjectVO.getProduce().getProducename());
                }
                if(focusProjectVO.getCo()!=null) {
                    row.createCell(3).setCellValue(focusProjectVO.getCo().getUsername());
                }
                if(focusProjectVO.getAe()!=null) {
                    row.createCell(4).setCellValue(focusProjectVO.getAe().getUsername());
                }
                row.createCell(5).setCellValue(focusProjectVO.getRemark());
                row.createCell(6).setCellValue(focusProjectVO.getTc());
                row.createCell(7).setCellValue(focusProjectVO.getPlannum());
                row.createCell(8).setCellValue(focusProjectVO.getPlancomoutnum());
                row.createCell(9).setCellValue(focusProjectVO.getPlanrate());
                row.createCell(10).setCellValue(focusProjectVO.getPo());
                row.createCell(11).setCellValue(focusProjectVO.getPotime());
                row.createCell(12).setCellValue(focusProjectVO.getPonum());
                row.createCell(13).setCellValue(focusProjectVO.getRealcomoutnum());
                row.createCell(14).setCellValue(focusProjectVO.getRealrate());
                row.createCell(15).setCellValue(focusProjectVO.getBillcode());
                row.createCell(16).setCellValue(focusProjectVO.getBillnum());
                row.createCell(17).setCellValue(focusProjectVO.getBilltime());
                row.createCell(18).setCellValue(focusProjectVO.getRertime());
                row.createCell(19).setCellValue(focusProjectVO.getStatusTypeVO().getValue());
            }else{
                row.createCell(6).setCellValue("计划金额合计");
                row.createCell(7).setCellValue(focusKpiDO.getKipnum());
                row.createCell(11).setCellValue("实际金额合计");
                row.createCell(12).setCellValue(focusKpiDO.getDoneponum());
                row.createCell(15).setCellValue("开票金额合计");
                row.createCell(16).setCellValue(focusKpiDO.getBillnum());
            }
        }
        try {
            FileOutputStream fout = new FileOutputStream(ExcelsavePath + adminUser.getUsername()+ PROJECTS);
            wb.write(fout);
            fout.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return ExcelexportPath + adminUser.getUsername()+ PROJECTS;
    }




    public static String kpiExcelexpot(List<FocusKpiVO> kpiList,FocusKpiDO kpiDO,FocusUserVO adminUser) {
        FileUtil.createdir(ExcelsavePath);
        //第一步创建workbook
        HSSFWorkbook wb = new HSSFWorkbook();
        //第二步创建sheet
        HSSFSheet sheet = wb.createSheet("销售KPI");
//        sheet.setColumnWidth((short)column,(short)width);
        //第三步创建行row:添加表头0行
        HSSFRow row = sheet.createRow(0);
        HSSFCellStyle  style = wb.createCellStyle();


        //第四步创建单元格

        createCell(row,0,style,"姓名",sheet,10);
        createCell(row,1,style,"年费季度",sheet,20);
        createCell(row,2,style,"指标量",sheet,25);
        createCell(row,3,style,"已完成量",sheet,25);
        createCell(row,4,style,"已开票量",sheet,25);
        for (int i = 0; i <= kpiList.size(); i++) {
            row = sheet.createRow(i+1);
            if(i<kpiList.size()){
            FocusKpiVO focusKpiVO = kpiList.get(i);
            //创建行

            //创建单元格并且添加数据
            if(focusKpiVO.getUser()!= null) {
                row.createCell(0).setCellValue(focusKpiVO.getUser().getUsername());
            }
            row.createCell(1).setCellValue(focusKpiVO.getPryear()+"年第"+focusKpiVO.getPrjidu()+"季度");
            row.createCell(2).setCellValue(focusKpiVO.getKipnum());
            row.createCell(3).setCellValue(focusKpiVO.getDoneponum());
            row.createCell(4).setCellValue(focusKpiVO.getBillnum());
             }else{
                row.createCell(1).setCellValue("合计");
                row.createCell(2).setCellValue(kpiDO.getKipnum());
                row.createCell(3).setCellValue(kpiDO.getDoneponum());
                row.createCell(4).setCellValue(kpiDO.getBillnum());
            }}
        try {
            FileOutputStream fout = new FileOutputStream(ExcelsavePath + adminUser.getUsername()+ KPIS);
            wb.write(fout);
            fout.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return ExcelexportPath + adminUser.getUsername()+ KPIS;
    }



    public static String kpiweekExcelexpot(List<FocusKpiVO> kpiList,FocusKpiDO kpiDO,FocusUserVO adminUser) {
        FileUtil.createdir(ExcelsavePath);
        //第一步创建workbook
        HSSFWorkbook wb = new HSSFWorkbook();
        //第二步创建sheet
        HSSFSheet sheet = wb.createSheet("周报表");
//        sheet.setColumnWidth((short)column,(short)width);
        //第三步创建行row:添加表头0行
        HSSFRow row = sheet.createRow(0);
        HSSFCellStyle  style = wb.createCellStyle();


        //第四步创建单元格

        createCell(row,0,style,"姓名",sheet,10);
        createCell(row,1,style,"周计划回款",sheet,20);
        createCell(row,2,style,"周已回款",sheet,25);
        createCell(row,3,style,"周欠款",sheet,25);
        for (int i = 0; i <= kpiList.size(); i++) {
            row = sheet.createRow(i+1);
            if(i<kpiList.size()){
                FocusKpiVO focusKpiVO = kpiList.get(i);
                //创建行

                //创建单元格并且添加数据
                if(focusKpiVO.getUser()!= null) {
                    row.createCell(0).setCellValue(focusKpiVO.getUser().getUsername());
                }
                row.createCell(1).setCellValue(focusKpiVO.getKipnum());
                row.createCell(2).setCellValue(focusKpiVO.getDoneponum());
                row.createCell(3).setCellValue(focusKpiVO.getBillnum());
            }else{
                row.createCell(0).setCellValue("合计");
                row.createCell(1).setCellValue(kpiDO.getKipnum());
                row.createCell(2).setCellValue(kpiDO.getDoneponum());
                row.createCell(3).setCellValue(kpiDO.getBillnum());
            }}
        try {
            FileOutputStream fout = new FileOutputStream(ExcelsavePath + adminUser.getUsername()+ WEEK);
            wb.write(fout);
            fout.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return ExcelexportPath + adminUser.getUsername()+ WEEK;
    }

    public static String kpimonthExcelexpot(List<FocusKpiVO> kpiList,FocusKpiDO kpiDO,FocusUserVO adminUser) {
        FileUtil.createdir(ExcelsavePath);
        //第一步创建workbook
        HSSFWorkbook wb = new HSSFWorkbook();
        //第二步创建sheet
        HSSFSheet sheet = wb.createSheet("月报表");
//        sheet.setColumnWidth((short)column,(short)width);
        //第三步创建行row:添加表头0行
        HSSFRow row = sheet.createRow(0);
        HSSFCellStyle  style = wb.createCellStyle();


        //第四步创建单元格

        createCell(row,0,style,"姓名",sheet,10);
        createCell(row,1,style,"月计划回款",sheet,25);
        createCell(row,2,style,"月开票金额",sheet,25);
        createCell(row,3,style,"月已回款",sheet,25);
        createCell(row,4,style,"月欠款",sheet,25);
        for (int i = 0; i <= kpiList.size(); i++) {
            row = sheet.createRow(i+1);
            if(i<kpiList.size()){
                FocusKpiVO focusKpiVO = kpiList.get(i);
                //创建行

                //创建单元格并且添加数据
                if(focusKpiVO.getUser()!= null) {
                    row.createCell(0).setCellValue(focusKpiVO.getUser().getUsername());
                }
                row.createCell(1).setCellValue(focusKpiVO.getKipnum());
                row.createCell(2).setCellValue(focusKpiVO.getBillnum());
                row.createCell(3).setCellValue(focusKpiVO.getDoneponum());
                row.createCell(4).setCellValue(focusKpiVO.getLendnum());
            }else{
                row.createCell(0).setCellValue("合计");
                row.createCell(1).setCellValue(kpiDO.getKipnum());
                row.createCell(2).setCellValue(kpiDO.getBillnum());
                row.createCell(3).setCellValue(kpiDO.getDoneponum());
                row.createCell(4).setCellValue(kpiDO.getLendnum());
            }}
        try {
            FileOutputStream fout = new FileOutputStream(ExcelsavePath + adminUser.getUsername()+ MONTH);
            wb.write(fout);
            fout.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return ExcelexportPath + adminUser.getUsername()+ MONTH;
    }

    public static String kpiquaterExcelexpot(List<FocusKpiVO> kpiList,FocusKpiDO kpiDO,FocusUserVO adminUser) {
        FileUtil.createdir(ExcelsavePath);
        //第一步创建workbook
        HSSFWorkbook wb = new HSSFWorkbook();
        //第二步创建sheet
        HSSFSheet sheet = wb.createSheet("季度报表");
//        sheet.setColumnWidth((short)column,(short)width);
        //第三步创建行row:添加表头0行
        HSSFRow row = sheet.createRow(0);
        HSSFCellStyle  style = wb.createCellStyle();


        //第四步创建单元格

        createCell(row,0,style,"姓名",sheet,10);
        createCell(row,1,style,"年费季度",sheet,20);
        createCell(row,2,style,"季度指标量",sheet,25);
        createCell(row,3,style,"季度开票量",sheet,25);
        createCell(row,4,style,"季度完成量",sheet,25);
        createCell(row,5,style,"季度欠款量",sheet,25);
        for (int i = 0; i <= kpiList.size(); i++) {
            row = sheet.createRow(i+1);
            if(i<kpiList.size()){
                FocusKpiVO focusKpiVO = kpiList.get(i);
                //创建行

                //创建单元格并且添加数据
                if(focusKpiVO.getUser()!= null) {
                    row.createCell(0).setCellValue(focusKpiVO.getUser().getUsername());
                }
                row.createCell(1).setCellValue(focusKpiVO.getPryear()+"年第"+focusKpiVO.getPrjidu()+"季度");
                row.createCell(2).setCellValue(focusKpiVO.getKipnum());
                row.createCell(3).setCellValue(focusKpiVO.getBillnum());
                row.createCell(4).setCellValue(focusKpiVO.getDoneponum());
                row.createCell(5).setCellValue(focusKpiVO.getLendnum());
            }else{
                row.createCell(1).setCellValue("合计");
                row.createCell(2).setCellValue(kpiDO.getKipnum());
                row.createCell(3).setCellValue(kpiDO.getBillnum());
                row.createCell(4).setCellValue(kpiDO.getDoneponum());
                row.createCell(5).setCellValue(kpiDO.getLendnum());
            }}
        try {
            FileOutputStream fout = new FileOutputStream(ExcelsavePath + adminUser.getUsername()+ QUATER);
            wb.write(fout);
            fout.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return ExcelexportPath + adminUser.getUsername()+ QUATER;
    }

    public static String kpiYearExcelexpot(List<FocusKpiVO> kpiList,FocusKpiDO kpiDO,FocusUserVO adminUser) {
        FileUtil.createdir(ExcelsavePath);
        //第一步创建workbook
        HSSFWorkbook wb = new HSSFWorkbook();
        //第二步创建sheet
        HSSFSheet sheet = wb.createSheet("季度报表");
//        sheet.setColumnWidth((short)column,(short)width);
        //第三步创建行row:添加表头0行
        HSSFRow row = sheet.createRow(0);
        HSSFCellStyle  style = wb.createCellStyle();


        //第四步创建单元格

        createCell(row,0,style,"姓名",sheet,10);
        createCell(row,1,style,"年份",sheet,20);
        createCell(row,2,style,"年PO金额",sheet,25);
        createCell(row,3,style,"年开票金额",sheet,25);
        createCell(row,4,style,"年回款金额",sheet,25);
        createCell(row,5,style,"年欠款金额",sheet,25);
        for (int i = 0; i <= kpiList.size(); i++) {
            row = sheet.createRow(i+1);
            if(i<kpiList.size()){
                FocusKpiVO focusKpiVO = kpiList.get(i);
                //创建行

                //创建单元格并且添加数据
                if(focusKpiVO.getUser()!= null) {
                    row.createCell(0).setCellValue(focusKpiVO.getUser().getUsername());
                }
                row.createCell(1).setCellValue(focusKpiVO.getPryear()+"年");
                row.createCell(2).setCellValue(focusKpiVO.getKipnum());
                row.createCell(3).setCellValue(focusKpiVO.getBillnum());
                row.createCell(4).setCellValue(focusKpiVO.getDoneponum());
                row.createCell(5).setCellValue(focusKpiVO.getLendnum());
            }else{
                row.createCell(1).setCellValue("合计");
                row.createCell(2).setCellValue(kpiDO.getKipnum());
                row.createCell(3).setCellValue(kpiDO.getBillnum());
                row.createCell(4).setCellValue(kpiDO.getDoneponum());
                row.createCell(5).setCellValue(kpiDO.getLendnum());
            }}
        try {
            FileOutputStream fout = new FileOutputStream(ExcelsavePath + adminUser.getUsername()+ YEAR);
            wb.write(fout);
            fout.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return ExcelexportPath + adminUser.getUsername()+ YEAR;
    }
    public static void createCell( HSSFRow row ,int index,HSSFCellStyle  style ,
                                   String name,HSSFSheet sheet,int width){
        HSSFCell   cell = row.createCell(index);                   //创建单元格的索引
        cell.setCellValue(name); //创建单元格的名字

        cell.setCellStyle(style);//创建单元格的类型
        sheet.setColumnWidth(index, width * 256);//创建单元格的宽度
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);  //居中
        style.setWrapText(true); //设置自动大小
    }

}